/*  SSSourceFormatter.m
 *  MESLib
 * 
 * Copyright 2003-2009 Starline Software Ltd
 * 
 * This file is part of MESLib.
 * 
 * MESLib is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MESLib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with MESLib. If not, see <http://www.gnu.org/licenses/>.
 */
//  Created by Tobias Haughton on Fri Nov 21 2003.
//

//SSSourceFormatter takes an array of strings and converts them into a string seperated by ,
//SSSourceFormatter then converts that string back to an array of strings when editinng is completed

#import "SSSourceFormatter.h"


@implementation SSSourceFormatter

- (BOOL)getObjectValue:(id *)anObject forString:(NSString *)string errorDescription:(NSString **)error
{
   //create an array from all of the values seperated by ,
   NSString *theString = [[string copy] autorelease];
   NSArray *array = [theString componentsSeparatedByString:@", "];
   
   *anObject = array;

   return YES;
}

- (NSAttributedString *)attributedStringForObjectValue:(id)anObject withDefaultAttributes:(NSDictionary *)attributes
{
   return nil;
}

- (NSString *)stringForObjectValue:(id)anObject
{
   if([anObject isKindOfClass:[NSString class]]) {
      return anObject;
   }
   
   if(![anObject isKindOfClass:[NSArray class]]) {
      return nil;
   }

   NSString *string = [NSString string];
   int i = 0;
   
   while(i < [anObject count]) {
      //build a string from our array
      string = [string stringByAppendingString:[anObject objectAtIndex:i]];
      i++;

      if(i < [anObject count]) {
         //we are going to add another value so add a ,
         string = [string stringByAppendingString:@", "];
      }
   }
      
   return string;
}

- (void)encodeWithCoder:(NSCoder *)coder
{
   [super encodeWithCoder:coder];
}

- (id)initWithCoder:(NSCoder *)coder
{
   self = [super initWithCoder:coder];

   return self;
}

@end
